
import _ from 'lodash'
import { Message } from 'element-ui'
import {
    materailOptimizeOne,
    materailOptimizeTwo,
    materailOptimizeThree,
    materailOptimizeFour,
    materailOptimizeFive,
    materailOptimizeSix,
    materailOptimizeSeven,
    materailOptimizeEight,
    materailOptimizeNine,
    changeParams,
    serviceOptimizeOne,
    serviceOptimizeTwo,
    serviceOptimizeFive
} from "./optimize"

// 推送商合进度提示消息
export const pushToShangheMessage = (isPush, pushMsg, equipCount, servCount) => {
    // 策略映射表（顺序敏感）
    const strategyMap = [
        {
            condition: () => isPush === "0" && pushMsg?.trim(), // 使用可选链和trim处理空字符串[1,4](@ref)
            result: {
                pushState: "0",
                promptMsg: `校验未通过，请根据提示进行处理，商合系统提示：${pushMsg}`
            }
        },
        {
            condition: () => isPush === "2",
            result: {
                pushState: "2",
                promptMsg: "请等待商合交易系统处理服务数据返回结果"
            }
        },
        {
            condition: () => isPush === "0" && servCount > 0,
            result: {
                pushState: "3",
                promptMsg: "请先点击【推送商合】按钮推送服务"
            }
        },
        {
            condition: () => isPush === "1" && equipCount > 0,
            result: {
                pushState: "1",
                promptMsg: "服务推送成功，请点击【推送商合】推送物资"
            }
        },
        {
            condition: () => isPush === "0" && equipCount > 0,
            result: {
                pushState: "4",
                promptMsg: "请先点击【推送商合】按钮推送物资"
            }
        },
        {
            condition: () => [servCount, equipCount].every(v => v == 0), // 统一判断零值[7](@ref)
            result: isPush === "1"
                ? { pushState: "6", promptMsg: "数据已推送商合成功" }
                : { pushState: "5", promptMsg: "数据未调整无需推送商合" }
        }
    ];

    // 策略匹配（找到第一个满足条件的策略）
    const matchedStrategy = strategyMap.find(({ condition }) => condition());

    return matchedStrategy?.result || {
        pushState: "7",
        promptMsg: "未知进度，请联系技术人员支撑"
    };
}
// 下一步提示消息信息
export const doNextMessageInfo = (nodeNameWord, userId, glEmpId, gcEmpId, shEmpId) => {
    let message = ''
    if (nodeNameWord === "correct_02") {//异常数据修改审核
        if (userId === glEmpId) {
            message = "已确认本项目前期存在未收货却进行到货确认错误，拟取消订单和转资情况属实。确认后将办理设备虚拟退库、订单退货操作，并核销工程成本。"
        }
        if (userId === gcEmpId) {
            message = "已确认对应订单工程应付款未发生过支付或已按订单金额全额追回应付款，已确认该资产卡片并未报废。确认后将办理取消转资、冲销已提折旧，并同步调减工程成本。"
        }
        if (userId === shEmpId) {
            message = "已确认本项目前期存在未收货却进行到货确认错误，并基于此事实已与供应商沟通，供应商同意“退货”。确认后将办理订单退货、取消，并核销工程应付账款。"
        }
    }
    if (nodeNameWord === "correct_021") {//地市资产管理员
        message = "已确认该资产交维时确实无实物，且截止目前未办理过资产报废。确认后将办理冲销对应资源系统已关联资产的资源。"
    }
    if (nodeNameWord === "correct_03") {//分管领导审批
        message = "请市分公司分管领导确认，该调整事项已经市/省公司总经理办公会审议、决策，同意调整。"
    }
    return message
}

// 切换判断是否修改数据
export const isChangeStatus = (materialList, serviecList, initObjInfo) => {
    const { initMaterialData, initServiceData } = initObjInfo
    const materialEditShow = materialList.some(item => (+item.status) === 1)
    const serviecEditShow = serviecList.some(item => (+item.status) === 1)
    // 深拷贝一份不影响表格数据
    const _newMaterialList = _.cloneDeep(materialList)
    const _newServiecList = _.cloneDeep(serviecList)
    // 删除id 进行比对是否更改了数据
    _newMaterialList.forEach(item => {
        delete item.id
    })
    _newServiecList.forEach(item => {
        delete item.id
    })
    const materialChange = _.isEqual(_newMaterialList, initMaterialData)
    const serviceChange = _.isEqual(_newServiecList, initServiceData)
    // 以这个为准是否更改数据了
    const materialChangeShow = materialEditShow && !materialChange
    const serviceChangeShow = serviecEditShow && !serviceChange
    return {
        materialChangeShow,
        serviceChangeShow
    }
}
// 物资是否可以编辑的逻辑
export function isMaterialEdit(row, item) {
    const prop = item.prop || item.property
    let flag = false
    flag = materailOptimizeOne(prop, row, flag)
    flag = materailOptimizeTwo(prop, row, flag)
    flag = materailOptimizeThree(prop, row, flag)
    flag = materailOptimizeFour(prop, row, flag)
    flag = materailOptimizeFive(prop, row, flag)
    flag = materailOptimizeSix(prop, row, flag)
    flag = materailOptimizeSeven(prop, row, flag)
    flag = materailOptimizeEight(prop, row, flag)
    flag = materailOptimizeNine(prop, row, flag)
    return flag
}
/**
 *
 * @param {*} row 当前行
 * @param {*} item 当前列信息
 * @param {*} saveValue 原始值
 */
export const handleSaveMaterialData = (row, item, saveValue) => {
    if (item.prop === 'changeNum') {
        materialupdateNum(row, item, saveValue)
    } else if (item.prop === 'disableNotUnusableStorage') {
        // 不可用不入库
        materialupdateDisableNotUNusableStorage(row, item, saveValue)
        changejingDu(row, item)
    } else if (item.prop === 'usableStorage') {
        // 可用入库
        materialupdateUsableStorage(row, item, saveValue)
        changejingDu(row, item)
    } else if (item.prop === 'unusableStorage') {
        // 不可用入库
        materialupdateUnusableStorage(row, item, saveValue)
        changejingDu(row, item)
    } else if (item.prop === 'notUsableStorage') {
        // 可用不入库
        materialupdateNotUsableStorage(row, item, saveValue)
        changejingDu(row, item)
    } else if (item.prop === 'notUnusableStorage') {
        // 不可用不入库
        materialupdateNotUNusableStorage(row, item, saveValue)
        changejingDu(row, item)
    } else {
        console.log("cancel");
    }
}
const changejingDu = (row, item) => {
    if (row[item.prop] === "") {
        row['changePrice'] = ""
        row['donePrice'] = ""
        row['doneTaxAmount'] = ""
        row['doneAmt'] = ""
    } else {
        row['changePrice'] = (+row['changePrice']) === 0 ? 0 : (+row['changePrice']).toFixed(2)
        row['donePrice'] = (+row['donePrice']) === 0 ? 0 : (+row['donePrice']).toFixed(2)
        row['doneTaxAmount'] = (+row['doneTaxAmount']) === 0 ? 0 : (+row['doneTaxAmount']).toFixed(2)
        row['doneAmt'] = (+row['doneAmt']) === 0 ? 0 : (+row['doneAmt']).toFixed(2)
    }
}
// 辅助函数 处理通用的值处理逻辑
const handleUniversalValues = (row, prop,) => {
    return ['', null].includes(row[prop]) ? "" : row[prop]
}
const isFloat = (n) => {
    return parseInt(n) < parseFloat(n);
}
// 调增数量
const materialupdateNum = (row, item, saveValue) => {
    // 没有修改还原默认值
    if (['0', "", null, undefined].includes(row[item.prop])) {
        row[item.prop] = ''
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        return
    }
    // 限制输入精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    const doneNum1 = parseFloat((+row['changeNum'])) + parseFloat((+row['amount']));
    // 开始计算逻辑
    row['status'] = 1
    //0-调增数量；1-调减数量；2-调增合价；3-调减合价
    row['changeStatus'] = (+row['changeNum']) > 0 ? '0' : '1'
    // 变化后合价(不含税)
    row['donePrice'] = (parseFloat((+doneNum1)) * parseFloat((+row['price']))).toFixed(2);
    // 合价(不含税)
    if (row['equipSum'] == null) {
        row['equipSum'] = 0;
    }
    // 税率
    if (['', null].includes(row['taxRate'])) {
        row['taxRate'] = 0;
    }
    row['changePrice'] = (parseFloat((+row['donePrice'])) - parseFloat((+row['equipSum']))).toFixed(2);
    row['doneTaxAmount'] = (parseFloat((+row['donePrice'])) * parseFloat((+row['taxRate']))).toFixed(2);
    row['doneAmt'] = (parseFloat((+row['donePrice'])) + parseFloat((+row['doneTaxAmount']))).toFixed(2);
    row['doneNum'] = doneNum1.toFixed(2)
}
// 无可用不入库
const OptimizeDisableNotUNusableStorageOne = (row) => {
    if (!(['', null].includes(row['doneNum']))) {
        row['disableNotUnusableStorage'] = 0;
        let doneNum1 = "";
        let sumNum = 0;
        // 赋值
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')

        sumNum = parseFloat(changeZeroBackValue(row['usableStorage'])) + parseFloat(changeZeroBackValue(row['unusableStorage'])) + parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage'])) + parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));

        if (sumNum > 0) {
            row['donePrice'] = parseFloat(+doneNum1) * parseFloat(+row['price']);

            if (row['equipSum'] == null) {
                row['equipSum'] = 0;
            }
            if (['', null].includes(row['taxRate'])) {
                row['taxRate'] = 0;
            }
            row['changePrice'] = parseFloat(row['donePrice']) - parseFloat(row['equipSum']);
            row['doneTaxAmount'] = parseFloat(row['donePrice']) * parseFloat(row['taxRate']);
            row['doneAmt'] = parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount']);
            row['noMaterialReduceAmount'] = "";
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            restorValues()
        }
    } else {
        restorValues()
    }
    // 还原默认值
    function restorValues() {
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['disableNotUnusableStorage'] = "";
        row['noMaterialReduceAmount'] = ''
        row['storemanName'] = "";
        row['storemanNum'] = "";
        row['storageAddress'] = "";
    }
}
const OptimizeDisableNotUNusableStorageTwo = (row, doneNum1) => {
    if (row['outPutType'] === '25' && row['powerCable'] === '1') {
        if (+row['disableNotUnusableStorage'] === +row['amount'] && youhuaOne(row)) {
            row['status'] = 1;
            //0-调增数量；1-调减数量；2-调增合价；3-调减合价
            row['changeStatus'] = "1";
            row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
            repeatValue_s(row)
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['noMaterialReduceAmount'] = (parseFloat(row['price']) * parseFloat(row['disableNotUnusableStorage'])).toFixed(2);
            row['doneNum'] = doneNum1.toFixed(2)
        } else {
            Message({
                message: `采购订单号"${row['orderNo']}"物资为利旧类电缆，仅允许选择一个有无实物下的退库类型将出库单数量整单退库！`,
                type: 'warning'
            })
            row['disableNotUnusableStorage'] = ''
            row['status'] = 0
            row['changePrice'] = ''
            return
        }
    } else {
        // 结果
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = "1";
        row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
        repeatValue_s(row)
        row['doneNum'] = doneNum1.toFixed(2)
        row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
        row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
        row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
        row['noMaterialReduceAmount'] = parseFloat(row['price']) * parseFloat(row['disableNotUnusableStorage']);
    }
}
const repeatValue_s = (row) => {
    if (row['equipSum'] == null) {
        row['equipSum'] = 0;
    }
    if (['', null].includes(row['taxRate'])) {
        row['taxRate'] = 0;
    }
}
// 处理if过多判断
const youhuaOne = (row) => {
    return !(changeParams(row['usableStorage']) && changeParams(row['unusableStorage']) && changeParams(row['notUsableStorage']) && changeParams(row['notUnusableStorage']))
}
// 处理如果为空则为0
const changeZeroBackValue = (value) => {
    return value || 0
}
// 无可用不入库
const materialupdateDisableNotUNusableStorage = (row, item, saveValue) => {
    if (['0', "", null, undefined].includes(row[item.prop])) {
        OptimizeDisableNotUNusableStorageOne(row)
        return
    }
    // 限制精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    //辅材
    if (isFloat(row['disableNotUnusableStorage']) && row['protype'] === '1') {
        Message({
            message: '输入不正确！主设备物资调减数量必须为正整数！',
            type: 'warning'
        })
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['disableNotUnusableStorage'] = "";
        row['noMaterialReduceAmount'] = ''
        return
    }
    let doneNum1 = ""
    if (['', null].includes(row['doneNum'])) {
        doneNum1 = parseFloat(row['amount']) - parseFloat(row['disableNotUnusableStorage']);
    } else {
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
    }
    if (doneNum1 < 0) {
        Message({
            message: '变化后数量”的计算结果不能为负数！',
            type: 'warning'
        })
        row['disableNotUnusableStorage'] = saveValue;
        return
    }
    OptimizeDisableNotUNusableStorageTwo(row, doneNum1)
}

// 可用入库
const OptimizematerialupdateUsableStorageOne = (row) => {
    if (!(['', null].includes(row['doneNum']))) {
        row['usableStorage'] = 0;
        let doneNum1 = "";
        let sumNum = 0;
        // 赋值
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        sumNum = parseFloat(changeZeroBackValue(row['usableStorage'])) + parseFloat(changeZeroBackValue(row['unusableStorage'])) + parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage'])) + parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));


        if (sumNum > 0) {
            row['donePrice'] = parseFloat(+doneNum1) * parseFloat(+row['price']);

            if (row['equipSum'] == null) {
                row['equipSum'] = 0;
            }
            if (['', null].includes(row['taxRate'])) {
                row['taxRate'] = 0;
            }
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            restorValues()
            row['storemanName'] = "";
            row['storemanNum'] = "";
            row['storageAddress'] = "";
        }
    } else {
        restorValues()
    }
    // 还原默认值
    function restorValues() {
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['usableStorage'] = "";
    }
}
// 可用入库
const OptimizematerialupdateUsableStorageTwo = (row, doneNum1) => {
    if (row['outPutType'] === '25' && row['powerCable'] === '1') {
        if (+row['usableStorage'] === +row['amount'] && youhuaOne(row)) {
            row['status'] = 1;
            //0-调增数量；1-调减数量；2-调增合价；3-调减合价
            row['changeStatus'] = "1";
            row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
            repeatValue_s(row)
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            Message({
                message: `采购订单号"${row['orderNo']}"物资为利旧类电缆，仅允许选择一个有无实物下的退库类型将出库单数量整单退库！`,
                type: 'warning'
            })
            row['usableStorage'] = ''
            row['status'] = 0
            row['changePrice'] = ''
            return
        }
    } else {
        // 结果
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = "1";
        row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
        repeatValue_s(row)
        row['doneNum'] = (+doneNum1).toFixed(2)
        row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
        row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
        row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
    }


}
// 可用入库
const materialupdateUsableStorage = (row, item, saveValue) => {
    if (['0', "", null, undefined].includes(row[item.prop])) {
        OptimizematerialupdateUsableStorageOne(row)
        return
    }
    // 限制精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    let doneNum1 = ""
    if (['', null].includes(row['doneNum'])) {
        doneNum1 = parseFloat(row['amount']) - parseFloat(row['usableStorage']);
    } else {
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
    }
    if (doneNum1 < 0) {
        Message({
            message: '变化后数量”的计算结果不能为负数！',
            type: 'warning'
        })
        row['usableStorage'] = saveValue;
        return
    }
    OptimizematerialupdateUsableStorageTwo(row, doneNum1)
}
// 不可用入库
const OptimizematerialupdateUnusableStorageOne = (row) => {
    if (!(['', null].includes(row['doneNum']))) {
        row['unusableStorage'] = 0;
        let doneNum1 = "";
        let sumNum = 0;
        // 赋值
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        sumNum = parseFloat(changeZeroBackValue(row['usableStorage'])) + parseFloat(changeZeroBackValue(row['unusableStorage'])) + parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage'])) + parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        if (sumNum > 0) {
            row['donePrice'] = (parseFloat(+doneNum1) * parseFloat(+row['price'])).toFixed(2);

            if (row['equipSum'] == null) {
                row['equipSum'] = 0;
            }

            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            restorValues()
            row['storemanName'] = "";
            row['storemanNum'] = "";
            row['storageAddress'] = "";
        }

    } else {
        restorValues()
    }
    // 还原默认值
    function restorValues() {
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['unusableStorage'] = "";
    }
}
const OptimizematerialupdateUnusableStorageTwo = (row, doneNum1) => {
    if (row['outPutType'] === '25' && row['powerCable'] === '1') {
        if (+row['unusableStorage'] === +row['amount'] && youhuaOne(row)) {
            row['status'] = 1;
            //0-调增数量；1-调减数量；2-调增合价；3-调减合价
            row['changeStatus'] = "1";
            row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
            repeatValue_s(row)
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            Message({
                message: `采购订单号"${row['orderNo']}"物资为利旧类电缆，仅允许选择一个有无实物下的退库类型将出库单数量整单退库！`,
                type: 'warning'
            })
            row['unusableStorage'] = ''
            row['status'] = 0
            row['changePrice'] = ''
            return
        }
    } else {
        // 结果
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = "1";
        row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
        repeatValue_s(row)
        row['doneNum'] = (+doneNum1).toFixed(2)
        row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
        row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
        row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
    }
}
// 不可用入库
const materialupdateUnusableStorage = (row, item, saveValue) => {
    if (['0', "", null, undefined].includes(row[item.prop])) {
        OptimizematerialupdateUnusableStorageOne(row)
        return
    }
    // 限制精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    //辅材
    if (isFloat(row['unusableStorage']) && row['protype'] === '1') {
        Message({
            message: '输入不正确！主设备物资调减数量必须为正整数！',
            type: 'warning'
        })
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['unusableStorage'] = "";
        return
    }
    let doneNum1 = ""
    if (['', null].includes(row['doneNum'])) {
        doneNum1 = parseFloat(row['amount']) - parseFloat(row['unusableStorage']);
    } else {
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
    }
    if (doneNum1 < 0) {
        Message({
            message: '变化后数量”的计算结果不能为负数！',
            type: 'warning'
        })
        row['unusableStorage'] = saveValue;
        return
    }
    OptimizematerialupdateUnusableStorageTwo(row, doneNum1)
}
const OptimizematerialupdateNotUsableStorageOne = (row) => {
    if (!(['', null].includes(row['doneNum']))) {
        row['notUsableStorage'] = 0;
        let doneNum1 = "";
        let sumNum = 0; //记录不可以入库、不可用不入库等是否填写
        let notSunNum = 0 //记录“不入库（不可用不入库、可用不入库）”字段是否填写
        // 赋值
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')

        sumNum = parseFloat(changeZeroBackValue(row['usableStorage'])) + parseFloat(changeZeroBackValue(row['unusableStorage'])) + parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage'])) + parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        notSunNum = parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage']));
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));

        if (sumNum > 0) {
            row['donePrice'] = parseFloat(+doneNum1) * parseFloat(+row['price']);
            repeatValue()
            if (!(notSunNum > 0)) {
                row['storemanName'] = "";
            }
            row['changePrice'] = parseFloat(row['donePrice']) - parseFloat(row['equipSum']);
            row['doneTaxAmount'] = parseFloat(row['donePrice']) * parseFloat(row['taxRate']);
            row['doneAmt'] = parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount']);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            restorValues()
            row['storemanName'] = "";
            row['storemanNum'] = "";
            row['storageAddress'] = "";
        }

    } else {
        restorValues()
    }
    function repeatValue() {
        if (row['equipSum'] == null) {
            row['equipSum'] = 0;
        }
        if (['', null].includes(row['taxRate'])) {
            row['taxRate'] = 0;
        }
    }
    // 还原默认值
    function restorValues() {
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['notUsableStorage'] = "";
    }
}
const OptimizematerialupdateNotUsableStorageTwo = (row, doneNum1) => {
    if (row['outPutType'] === '25' && row['powerCable'] === '1') {
        if (+row['notUsableStorage'] === +row['amount'] && youhuaOne(row)) {
            row['status'] = 1;
            //0-调增数量；1-调减数量；2-调增合价；3-调减合价
            row['changeStatus'] = "1";
            row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
            repeatValue_s(row)
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
            repeat()
        } else {
            Message({
                message: `采购订单号"${row['orderNo']}"物资为利旧类电缆，仅允许选择一个有无实物下的退库类型将出库单数量整单退库！`,
                type: 'warning'
            })
            row['notUsableStorage'] = ''
            row['status'] = 0
            row['changePrice'] = ''
            return
        }
    } else {
        // 结果
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = "1";
        row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
        repeatValue_s(row)
        row['doneNum'] = (+doneNum1).toFixed(2)
        row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
        row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
        row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
        repeat()
    }

    function repeat() {
        if (row['fieldProjectManager'] !== '1') {
            row['storemanName'] = row['fieldProjectManager']
        }
    }
}
// 可用不入库
const materialupdateNotUsableStorage = (row, item, saveValue) => {
    if (['0', "", null, undefined].includes(row[item.prop])) {
        OptimizematerialupdateNotUsableStorageOne(row)
        return
    }
    // 限制精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    //辅材
    if (isFloat(row['notUsableStorage']) && row['protype'] === '1') {
        Message({
            message: '输入不正确！主设备物资调减数量必须为正整数！',
            type: 'warning'
        })
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['notUsableStorage'] = "";
        row['storemanName'] = ''
        return
    }

    let doneNum1 = ""
    if (['', null].includes(row['doneNum'])) {
        doneNum1 = parseFloat(row['amount']) - parseFloat(row['notUsableStorage']);
    } else {
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
    }
    if (doneNum1 < 0) {
        Message({
            message: '变化后数量”的计算结果不能为负数！',
            type: 'warning'
        })
        row['notUsableStorage'] = saveValue;
        return
    }
    OptimizematerialupdateNotUsableStorageTwo(row, doneNum1)
}
const OptimizematerialupdateNotUNusableStorageOne = (row) => {
    if (!(['', null].includes(row['doneNum']))) {
        row['notUnusableStorage'] = 0;
        let doneNum1 = "";
        let sumNum = 0; //记录不可以入库、不可用不入库等是否填写
        let notSunNum = 0 //记录“不入库（不可用不入库、可用不入库）”字段是否填写
        // 赋值
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')

        sumNum = parseFloat(changeZeroBackValue(row['usableStorage'])) + parseFloat(changeZeroBackValue(row['unusableStorage'])) + parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage'])) + parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
        notSunNum = parseFloat(changeZeroBackValue(row['notUsableStorage'])) + parseFloat(changeZeroBackValue(row['notUnusableStorage']));
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));

        if (sumNum > 0) {
            row['donePrice'] = parseFloat(+doneNum1) * parseFloat(+row['price']);
            repeatValue()
            if (!(notSunNum > 0)) {
                row['storemanName'] = "";
            }
            row['changePrice'] = parseFloat(row['donePrice']) - parseFloat(row['equipSum']);
            row['doneTaxAmount'] = parseFloat(row['donePrice']) * parseFloat(row['taxRate']);
            row['doneAmt'] = parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount']);
            row['doneNum'] = (+doneNum1).toFixed(2)
        } else {
            restorValues()
            row['storemanName'] = "";
            row['storemanNum'] = "";
            row['storageAddress'] = "";
        }

    } else {
        restorValues()
    }
    function repeatValue() {
        if (row['equipSum'] == null) {
            row['equipSum'] = 0;
        }
        if (['', null].includes(row['taxRate'])) {
            row['taxRate'] = 0;
        }
    }
    // 还原默认值
    function restorValues() {
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['notUnusableStorage'] = "";
    }
}
const OptimizematerialupdateNotUNusableStorageTwo = (row, doneNum1) => {
    if (row['outPutType'] === '25' && row['powerCable'] === '1') {
        if (+row['notUnusableStorage'] === +row['amount'] && youhuaOne(row)) {
            row['status'] = 1;
            //0-调增数量；1-调减数量；2-调增合价；3-调减合价
            row['changeStatus'] = "1";
            row['donePrice'] = (+ parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
            repeatValue_s(row)
            row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
            row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
            row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
            row['doneNum'] = (+doneNum1).toFixed(2)
            repeat()
        } else {
            Message({
                message: `采购订单号"${row['orderNo']}"物资为利旧类电缆，仅允许选择一个有无实物下的退库类型将出库单数量整单退库！`,
                type: 'warning'
            })
            row['notUnusableStorage'] = ''
            row['status'] = 0
            row['changePrice'] = ''
            return
        }
    } else {
        // 结果
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = "1";
        row['donePrice'] = (parseFloat(doneNum1) * parseFloat(row['price'])).toFixed(2);
        repeatValue_s(row)
        row['doneNum'] = (+doneNum1).toFixed(2)
        row['changePrice'] = (parseFloat(row['donePrice']) - parseFloat(row['equipSum'])).toFixed(2);
        row['doneTaxAmount'] = (parseFloat(row['donePrice']) * parseFloat(row['taxRate'])).toFixed(2);
        row['doneAmt'] = (parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount'])).toFixed(2);
        repeat()
    }


    function repeat() {
        if (row['fieldProjectManager'] !== '1') {
            row['storemanName'] = row['fieldProjectManager']
        }
    }
}
// notUnusableStorage
const materialupdateNotUNusableStorage = (row, item, saveValue) => {
    if (['0', "", null, undefined].includes(row[item.prop])) {
        OptimizematerialupdateNotUNusableStorageOne(row)
        return
    }
    // 限制精度
    if (!/^(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop])) {
        Message({
            message: '输入不正确！请输入最多四位小数的正数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    }
    //辅材
    if (isFloat(row['notUnusableStorage']) && row['protype'] === '1') {
        Message({
            message: '输入不正确！主设备物资调减数量必须为正整数！',
            type: 'warning'
        })
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['notUnusableStorage'] = "";
        row['storemanName'] = ''
        return
    }
    let doneNum1 = ""
    if (['', null].includes(row['doneNum'])) {
        doneNum1 = parseFloat(row['amount']) - parseFloat(row['notUnusableStorage']);
    } else {
        row['usableStorage'] = handleUniversalValues(row, 'usableStorage')
        row['unusableStorage'] = handleUniversalValues(row, 'unusableStorage')
        row['notUsableStorage'] = handleUniversalValues(row, 'notUsableStorage')
        row['notUnusableStorage'] = handleUniversalValues(row, 'notUnusableStorage')
        row['disableNotUnusableStorage'] = handleUniversalValues(row, 'disableNotUnusableStorage')
        doneNum1 = parseFloat(row['amount']) - parseFloat(changeZeroBackValue(row['usableStorage'])) - parseFloat(changeZeroBackValue(row['unusableStorage'])) - parseFloat(changeZeroBackValue(row['notUsableStorage'])) - parseFloat(changeZeroBackValue(row['notUnusableStorage'])) - parseFloat(changeZeroBackValue(row['disableNotUnusableStorage']));
    }
    if (doneNum1 < 0) {
        Message({
            message: '变化后数量”的计算结果不能为负数！',
            type: 'warning'
        })
        row['notUnusableStorage'] = saveValue;
        return
    }
    OptimizematerialupdateNotUNusableStorageTwo(row, doneNum1)
}


// 服务是否可以编辑的逻辑
export function isServiceEdit(row, item) {
    const { billType, equipSum, amount, isAdjustOrder, isAdjustSupplier } = row
    // ifChangeSer
    const prop = item.prop || item.property
    let flag = false
    if (serviceOptimizeSeven(isAdjustOrder === '1', prop !== 'ifChangeSer')) {
        flag = false
        return flag
    }
    if (serviceOptimizeSeven(isAdjustSupplier === '1', prop === 'ifChangeSer')) {
        flag = false
        return flag
    }
    //在建损失订单 负数订单不允许编辑
    if (([30, 46].includes(+billType) || (+equipSum) < 0) && prop !== 'ifChangeSer') {
        flag = false
        return flag
    }
    //订单数量为0的情况下，只允许调增，且只支持调增变化数量
    if (serviceOptimizeSeven(+amount === 0, true)) {
        const enum_obj = {
            changeNum: true,
            adjustedPrice: false,
            changePrice: false,
        }
        flag = enum_obj[prop]
        return flag
    }
    //默认可以勾选是否变更供应商，如果变化合价、变化数量、变化后单价用户进行了填写，那么就不允许勾选该字段。
    flag = serviceOptimizeSix(prop, flag)
    flag = serviceOptimizeOne(prop, row, flag)
    flag = serviceOptimizeTwo(prop, row, flag)
    flag = serviceOptimizeFive(prop, row, flag)
    return flag
}
const serviceOptimizeSix = (prop, state) => {
    let flag = state;
    if (prop === "ifChangeSer") {
        flag = true;//可以编辑
    }
    return flag
}
const serviceOptimizeSeven = (tyep1, type2) => {
    return tyep1 && type2
}
/**
 *
 * @param {*} row 当前行
 * @param {*} item 当前列信息
 * @param {*} saveValue 原始值
 * @param {*} initTableData 初始化表格数据
 * @param {*} _copyRow 拷贝的行数据
 */
export const handleSaveServiceData = (row, item, saveValue, initTableData, _copyRow,softWort) => {
    if (item.prop === 'changeNum') {
        sericeupdateNum(row, item, saveValue, initTableData, _copyRow,softWort)
    } else if (item.prop === 'changePrice') {
        sericeupdatePrice(row, item, saveValue, initTableData, _copyRow)
    } else if (item.prop === 'adjustedPrice') {
        sericeupdateAdjustedPrice(row, item, saveValue, initTableData, _copyRow)
    } else {
        console.log("cancel");
    }
}
const isBackInfo = (tableData, row) => {
    const findList = tableData.filter(item => item.orderNo === row.orderNo && item.categoryCode === row.categoryCode)
    // 合价不含税累计合计
    let sumTotal = findList.reduce((accumulator, currentObject) => (+accumulator) + (+currentObject.equipSum), 0)
    return sumTotal
}


const OptimizesericeupdateNumOne = (row, item, saveValue) => {
    // 旧三包数量只能是整数 其它数量最多4位小数
    if (!["", null, undefined].includes(row[item.prop])) {
        // 三包
        if (row['ifsb'] !== '0' && !(/^-?(0|[1-9]\d*)$/.test(row[item.prop]))) {
            Message({
                message: '输入不正确！三包类的服务订单数量调整时必须为整数！',
                type: 'warning'
            })
            row[item.prop] = saveValue
            throw ''
        }
        // 非三包
        if (!(/^-?(0|[1-9]\d*)(\.\d{1,4})?$/.test(row[item.prop]))) {
            Message({
                message: row['ifsb'] !== '0' ? '输入不正确！三包类的服务订单数量调整时必须为整数！' : '输入不正确！只能输入最多四位小数的数据！',
                type: 'warning'
            })
            row[item.prop] = saveValue
            throw ''
        }
    }
}
const OptimizesericeupdateNumTwo = (row, item, saveValue, initTableDatas) => {
    //如果合价不含税累计小于等于0只能调增不能调减
    if (item.prop == "changeNum" && isBackInfo(initTableDatas, row) <= 0 && (+row['changeNum']) < 0) {
        Message({
            message: '"当前调整订单及同订单累计合价（不含税）金额小于等于零，只可输入正数，不可输入负数"',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
}
const OptimizesericeupdateNumThree = (row, item, saveValue, doneNum1) => {
    if (isFloat(doneNum1) && row['ifsb'] !== '0') {
        Message({
            message: '输入不正确！三包类的服务订单数量调整时必须为整数！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
    if (+doneNum1 < 0) {
        Message({
            message: '服务订单数量调减时，调减数量不能超过原订单的数量！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
    // 没有修改还原默认值
    if (['0', "", null, undefined].includes(row[item.prop])) {
        row[item.prop] = ''
        row['status'] = 0;
        row['doneNum'] = "";
        row['donePrice'] = "";
        row['changePrice'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['adjustedPrice'] = ""
        throw ''
    }
}
const OptimizesericeupdateNumFour = (row) => {
    return (['4', '14'].includes(row['epcServiceType']) || row['ifRoomService'] === "1" || row['codeBusClassification'] === "14") && +row['master'] > 0
}
const sericeupdateNum = (row, item, saveValue, initTableDatas, _copyDataRow,softWort) => {
    // 旧三包数量只能是整数 其它数量最多4位小数
    // 修复阻断
    OptimizesericeupdateNumOne(row, item, saveValue)
    //如果合价不含税累计小于等于0只能调增不能调减
    OptimizesericeupdateNumTwo(row, item, saveValue, initTableDatas)
    let doneNum1 = parseFloat(row['changeNum']) + parseFloat(row['amount']);
    OptimizesericeupdateNumThree(row, item, saveValue, doneNum1)
    // 结算逻辑
    if (!([0, ""].includes(+row['changeNum']))) {
        row['status'] = 1;
        //0-调增数量；1-调减数量；2-调增合价；3-调减合价
        row['changeStatus'] = +row['changeNum'] > 0 ? '0' : '1'
        row['donePrice'] = softNumCalcTwo(row,doneNum1,softWort);
        //总包服务订单在项目结算调整时，如果该站址总包服务的构成明细中含有主设备物资，那么系统管控当前总包服务订单的合价金额不允许调整为0。
        if (+row['donePrice'] === 0 && OptimizesericeupdateNumFour(row)) {
            Message({
                message: '总包服务、砖混/框架机房服务、外电引入施工服务订单的合价金额不允许调整为0！',
                type: 'warning'
            })
            row[item.prop] = saveValue
            return
        }
        if (row['equipSum'] == null) {
            row['equipSum'] = 0;
        }
        if (["", null].includes(row['taxRate'])) {
            row[taxRate] = 0;
        }
        row['changePrice'] = softNumCalc(row,softWort);
        row['doneTaxAmount'] = parseFloat(row['donePrice']) * parseFloat(row['taxRate']);
        row['doneAmt'] = parseFloat(row['donePrice']) + parseFloat(row['doneTaxAmount']);
        let donePrice1 = Math.round(row['donePrice'] * 100) / 100;
        let changePrice1 = Math.round(row['changePrice'] * 100) / 100;
        // 计算出来的变化后合价和不含税合价一致还原默认值
        if ((+donePrice1) === (+row['equipSum'])) {
            Message({
                message: '变化数量的值所填过小，变化合价为0，无法推送商合，请重新填写',
                type: 'warning'
            })
            row['status'] = _copyDataRow.status;
            row['changeNum'] = _copyDataRow.changeNum;
            row['doneNum'] = _copyDataRow.doneNum;
            row['donePrice'] = _copyDataRow.donePrice;
            row['changePrice'] = _copyDataRow.changePrice;
            row['changeStatus'] = _copyDataRow.changeStatus;
            row['doneAmt'] = _copyDataRow.doneAmt;
            row['doneTaxAmount'] = _copyDataRow.doneTaxAmount;
            row['adjustedPrice'] = _copyDataRow.adjustedPrice;
            return
        }
        let doneTaxAmount1 = Math.round((+row['doneTaxAmount']) * 100) / 100;
        let doneAmt1 = Math.round((+row['doneAmt']) * 100) / 100;
        row['adjustedPrice'] = "";
        row['doneNum'] = doneNum1;
        row['changePrice'] = changePrice1
        row['donePrice'] = donePrice1;
        row['doneAmt'] = doneAmt1;
        row['doneTaxAmount'] = doneTaxAmount1;

    }
}
const softNumCalc=(row,softWort)=>{
    let result = ''
    if(softWort||+row['amount']===0){
        result = row['changePrice']
    }else{
        result = (parseFloat(row['donePrice']) - parseFloat(row['equipSum']))
    }
    return result
}
const softNumCalcTwo = (row, doneNum1,softWort) => {
    let result = ''
    if (softWort || +row['amount'] === 0) {
        row['changePrice'] = (parseFloat(row['changeNum']) * parseFloat(row['price']))
        result = (+row['equipSum']) + (+row['changePrice'])
    } else {
        result = parseFloat(doneNum1) * parseFloat(row['price'])
    }
    return result
}
const OptimizesericeupdatePriceOne = (row, item, saveValue, initTableDatas) => {
    //如果合价不含税累计小于等于0只能调增不能调减
    if (item.prop == "changePrice" && isBackInfo(initTableDatas, row) <= 0 && (+row['changePrice']) < 0) {
        Message({
            message: "当前调整订单及同订单累计合价（不含税）金额小于等于零，只可输入正数，不可输入负数",
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
    //累计合价不含税金额 > 0 调减的金额不能大于累计合价不含税金额
    if (item.prop === "changePrice" && (+row['changePrice']) < 0 && Math.abs(+row['changePrice']) > Math.abs(isBackInfo(initTableDatas, row))) {
        Message({
            message: "调减的金额不能大于累计合价不含税金额",
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
}
const OptimizesericeupdatePriceTwo = (row, item, saveValue, donePrice1) => {
    //总包服务订单在项目结算调整时，如果该站址总包服务的构成明细中含有主设备物资，那么系统管控当前总包服务订单的合价金额不允许调整为0。
    if (donePrice1 == 0 && OptimizesericeupdateNumFour(row)) {
        Message({
            message: '总包服务、砖混/框架机房服务、外电引入施工服务订单的合价金额不允许调整为0！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ""
    }
    if (donePrice1 < 0) {
        Message({
            message: '服务订单金额调减时，调减金额不能超过原订单的金额！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ""
    }
    // 还原默认值
    if (!changeParams(row[item.prop])) {
        row[item.prop] = ''
        row['status'] = 0;
        row['donePrice'] = "";
        row['changeNum'] = ""
        row['doneNum'] = "";
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        row['adjustedPrice'] = ""
        throw ""
    }
    // 金额最多有两位小数
    if (!(/^-?(0|[1-9]\d*)(\.\d{1,2})?$/.test(row[item.prop]))) {
        Message({
            message: '输入不正确！只能输入最多两位小数的数据！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
}
const sericeupdatePrice = (row, item, saveValue, initTableDatas, _copyDataRow) => {
    OptimizesericeupdatePriceOne(row, item, saveValue, initTableDatas)
    let donePrice1 = parseFloat(row['changePrice']) + parseFloat(row['equipSum']);
    OptimizesericeupdatePriceTwo(row, item, saveValue, donePrice1)
    if (!(["", 0].includes(+row['changePrice']))) {
        row['status'] = 1;
        //2-调增合价；3-调减合价
        row['changeStatus'] = +row['changePrice'] > 0 ? "2" : "3";
        if (["", null].includes(row['taxRate'])) {
            row['taxRate'] = 0;
        }
        if ((+row['changePrice']) < 0 && +donePrice1 === 0) {
            row['doneNum'] = "0";
            row['changeNum'] = -row['amount'];
        } else {
            row['doneNum'] = row['amount'];
            row['changeNum'] = "0";
        }
        row['doneTaxAmount'] = parseFloat(donePrice1) * parseFloat(row['taxRate']);
        row['doneAmt'] = parseFloat(donePrice1) + parseFloat(row['doneTaxAmount']);
        let changePrice1 = Math.round(row['changePrice'] * 100) / 100;
        let donPrice2 = Math.round(donePrice1 * 100) / 100;
        let doneAmt1 = Math.round(row['doneAmt'] * 100) / 100;
        let doneTaxAmount1 = Math.round(row['doneTaxAmount'] * 100) / 100;
        row['adjustedPrice'] = "";
        row['changePrice'] = changePrice1;
        row['donePrice'] = donPrice2;
        row['doneAmt'] = doneAmt1;
        row['doneTaxAmount'] = doneTaxAmount1;
    }
}
const OptimizesericeupdateAdjustedPriceOne = (row, item, saveValue) => {
    if (["", null].includes(row[item.prop]) || +row['adjustedPrice'] === +row['price']) {
        row[item.prop] = ''
        row['status'] = 0;
        row['changePrice'] = "";
        row['donePrice'] = "";
        row['doneNum'] = "";
        row['changeNum'] = ""
        row['changeStatus'] = "";
        row['doneAmt'] = "";
        row['doneTaxAmount'] = "";
        throw ''
    }
    if (Math.abs(parseFloat(row[item.prop])) < 0.005) {
        row['adjustedPrice'] = 0;
    }
    if (+row['adjustedPrice'] === 0) {
        Message({
            message: '调增后单价不能为0!',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
    // 金额最多有两位小数
    if (!(/^-?(0|[1-9]\d*)(\.\d{1,2})?$/.test(row[item.prop]))) {
        Message({
            message: '输入不正确！只能输入最多两位小数的数据！',
            type: 'warning'
        })
        row[item.prop] = saveValue
        throw ''
    }
}
const OptimizesericeupdateAdjustedPriceTwo = (row, item, initTableDatas, _copyDataRow) => {
    //如果合价不含税累计小于等于0只能调增不能调减
    if (item.prop === "adjustedPrice" && isBackInfo(initTableDatas, row) <= 0 && (+row['adjustedPrice']) < 0) {
        Message({
            message: "当前调整订单及同订单累计合价（不含税）金额小于等于零，只可输入正数，不可输入负数",
            type: 'warning'
        })
        row['adjustedPrice'] = _copyDataRow.adjustedPrice;
        row['status'] = _copyDataRow.status;
        throw ''
    }
    //累计合价不含税金额 > 0 调减的金额不能大于累计合价不含税金额
    if (item.prop === "adjustedPrice" && (+row['adjustedPrice']) < 0 && Math.abs(+row['adjustedPrice']) > Math.abs(isBackInfo(initTableDatas, row))) {
        Message({
            message: "调减的金额不能大于累计合价不含税金额",
            type: 'warning'
        })
        row['adjustedPrice'] = _copyDataRow.adjustedPrice;
        row['status'] = _copyDataRow.status;
        throw ''
    }
}
const OptimizesericeupdateAdjustedPriceThree = (row, _copyDataRow) => {
    if (+row['changePrice'] === 0) {
        row['adjustedPrice'] = _copyDataRow.adjustedPrice;
        row['changePrice'] = _copyDataRow.changePrice;
        row['donePrice'] = _copyDataRow.donePrice;
        row['doneNum'] = _copyDataRow.doneNum;
        row['changeNum'] = _copyDataRow.changeNum;
        row['status'] = _copyDataRow.status;
        row['changeStatus'] = _copyDataRow.changeStatus;
        row['doneAmt'] = _copyDataRow.doneAmt;
        row['doneTaxAmount'] = _copyDataRow.doneTaxAmount;
        throw ''
    }
    if (['', null].includes(row['taxRate'])) {
        row['taxRate'] = 0;
    }
}
const sericeupdateAdjustedPrice = (row, item, saveValue, initTableDatas, _copyDataRow) => {
    OptimizesericeupdateAdjustedPriceOne(row, item, saveValue)
    OptimizesericeupdateAdjustedPriceTwo(row, item, initTableDatas, _copyDataRow)
    //调整后金额 = 调整后单价 * 数量
    let donePrice1 = parseFloat(row['adjustedPrice']) * parseFloat(row['amount']);

    if (donePrice1 < 0) {
        Message({
            message: "调整后合价”的计算结果不能为负数！",
            type: 'warning'
        })
        row[item.prop] = saveValue
        return
    } else {
        if (Math.abs(parseFloat(row['adjustedPrice'])) < 0.005) {
            row['adjustedPrice'] = 0;
        }
        row['changePrice'] = donePrice1 - (+row['equipSum']);
        row['status'] = 1
        row['changeStatus'] = +row['changePrice'] > 0 ? '4' : '5'
        OptimizesericeupdateAdjustedPriceThree(row, _copyDataRow)
        /* 订单金额调增时填写正数，调整数量默认为0
         订单金额部分调减时填写负数，调整数量默认为0
         订单金额全部调减时填写负数，调整数量默认为订单原始数量的负数 */
        if (+row['changePrice'] < 0 && +donePrice1 === 0) {
            row['doneNum'] = "0";
            row['changeNum'] = 0; //-amount
        } else {
            row['doneNum'] = row['amount'];
            row['changeNum'] = "0";
        }
        row['doneTaxAmount'] = parseFloat(donePrice1) * parseFloat(row['taxRate']);
        row['doneAmt'] = parseFloat(donePrice1) + parseFloat(row['doneTaxAmount']);
        let changePrice1 = Math.round(row['changePrice'] * 100) / 100;
        let donPrice2 = Math.round(donePrice1 * 100) / 100;
        let doneAmt1 = Math.round(row['doneAmt'] * 100) / 100;
        let doneTaxAmount1 = Math.round(row['doneTaxAmount'] * 100) / 100;
        row['changePrice'] = changePrice1;
        row['donePrice'] = donPrice2;
        row['doneAmt'] = doneAmt1;
        row['doneTaxAmount'] = doneTaxAmount1;
    }

}


